package com.example.noval.ui.adapter.decoration

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

/**
 * @Description
 * @Author zzl
 * @Date 2024/3/26
 */
class LinearItemDecoration: RecyclerView.ItemDecoration() {

//    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
//        with(outRect) {
////            if (parent.getChildAdapterPosition(view) != 0) {
////                top =20 
////            }
//            top=20
//            bottom=20
//        }
//    }

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        val layoutManager = parent.layoutManager
        val layoutParams = view.layoutParams as RecyclerView.LayoutParams
        val position = layoutParams.viewAdapterPosition

        // 设置左右间距
        outRect.top = 20
        outRect.bottom = 20
        outRect.left = 16
        outRect.right = 16
        // 在每行的第一个项之前不添加顶部间距
    }
    
    
}